package com.ctshk.app.system.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.MainDataBusinessDTO;
import com.ctshk.rpc.system.req.MainDataBusinessListReq;
import com.ctshk.rpc.system.req.MainDataBusinessReq;
import com.ctshk.rpc.system.service.IMainDataBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 办证中心 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-04-02
 */
@Api(value = "主數據办证中心",tags = "主數據办证中心")
@RestController
@RequestMapping("/main-data-business")
public class MainDataBusinessController extends BaseController {
    @DubboReference
    private IMainDataBusinessService iMainDataBusinessService;

    @ApiOperation(value = "列表", notes = "列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "列表", operDesc = "列表")
    @PostMapping("/list")
    public Result<PageResponse<MainDataBusinessDTO>> list(@RequestBody MainDataBusinessListReq req) {
        return iMainDataBusinessService.list(req);
    }

    @ApiOperation(value = "详情", notes = "详情")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "详情", operDesc = "详情")
    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable Long id) {
        return iMainDataBusinessService.detail(id);
    }


    @ApiOperation(value="新增", notes="新增")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增", operDesc = "新增")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid MainDataBusinessReq req){
        return iMainDataBusinessService.add(req,getCurrentUser(getRequest()));
    }


    @ApiOperation(value="編輯", notes="編輯")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "編輯", operDesc = "編輯")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid MainDataBusinessReq req){
        return iMainDataBusinessService.update(req,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.DELETE, operTitle = "删除", operDesc = "删除")
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        return iMainDataBusinessService.delete(id);
    }
}
